<?php

namespace app\admin\controller\login;

use app\admin\service\login\LoginService;
use app\admin\validate\login\LoginValidate;
use app\admin\controller\AdminController;
use think\response\Json;

/**
 * 管理员登录控制器
 */
class Login extends AdminController
{
    /**
     * 账号登录
     * @return Json
     */
    public function login()
    {
        $params = (new LoginValidate())->post()->checkParam();
        $res = LoginService::login($params);
        if($res) {
            return $this->success($res);
        } else {
            return $this->error(LoginService::getError());
        }
    }

    /**
     * 退出登录
     * @return Json
     */
    public function logout()
    {
        (new LoginService())->logout($this->adminInfo);
        return $this->success();
    }
}